//
//  CDVShowVideoPlaybackView.m
//  Staff
//
//  Created by caiyao on 11/13/14.
//
//

#import "CDVShowVideoPlaybackView.h"
#import "VideoPlaybackViewController.h"
#import "AppDelegate.h"
#import "ScanNavigationController.h"
#import "NotificationDefine.h"
#import "QRCodeViewController.h"

@interface CDVShowVideoPlaybackView ()

@property(strong, nonatomic)NSString *scanCallbackId;

@end

@implementation CDVShowVideoPlaybackView

- (void)showVideoPlaybackView:(CDVInvokedUrlCommand*)command
{
    
//    Class vcClass = NSClassFromString(@"VideoPlaybackViewController");
//    id vc = [[vcClass alloc]  initWithNibName:nil bundle:nil];
    
    ScanNavigationController *scanNavigationController = [[ScanNavigationController alloc]init];
    [[(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController] presentViewController:scanNavigationController animated:NO completion:NULL];
    
    CDVPluginResult* pluginResult = nil;
    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil];
    [self.commandDelegate sendPluginResult:pluginResult
                                callbackId:command.callbackId];
    
    
}



- (void)showVideoPlaybackViewAndReceiveScan:(CDVInvokedUrlCommand*)command{
    self.scanCallbackId = [command callbackId];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(notificationScanResult:) name:NotificationScanResult object:nil];
}

-(void)dealloc{
    [super dealloc];
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}


-(void)notificationScanResult:(NSNotification*)notification{
    CDVPluginResult *pluginResult = [notification object];
    [self.commandDelegate sendPluginResult:pluginResult
                                callbackId:self.scanCallbackId];
    
}

@end
